<?php
class ChartersController extends AppController {

	var $name = 'Charters';

	function index() {
            $this->set('title_for_layout', 'Datos Judiciales - Fueros');
		$this->Charter->recursive = 0;
		$this->set('charters', $this->paginate());
	}

	function view($id = null) {
            $this->set('title_for_layout', 'Datos Judiciales - Fueros');
		if (!$id) {
			$this->Session->setFlash(__('Invalid charter', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('charter', $this->Charter->read(null, $id));
	}

	function add() {
             $this->set('title_for_layout', 'Datos Judiciales - Fueros');
		if (!empty($this->data)) {
			$this->Charter->create();
			if ($this->Charter->save($this->data)) {
				$this->Session->setFlash(__('The charter has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The charter could not be saved. Please, try again.', true));
			}
		}
		$jurisdictions = $this->Charter->Jurisdictions->find('list',array('fields'=>'descripcion'));
		$this->set(compact('jurisdictions'));
	}

	function edit($id = null) {
             $this->set('title_for_layout', 'Datos Judiciales - Fueros');
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid charter', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Charter->save($this->data)) {
				$this->Session->setFlash(__('The charter has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The charter could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Charter->read(null, $id);
		}
		$juridictions = $this->Charter->Jurisdictions->find('list',array('fields'=>'descripcion'));
                $this->log($juridictions);
		$this->set(compact('juridictions'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for charter', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Charter->delete($id)) {
			$this->Session->setFlash(__('Charter deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Charter was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
